package com.alisls.shequtao.service.user.service.impl;

import com.alisls.shequtao.service.user.constant.UserExceptionEnum;
import com.alisls.shequtao.service.user.dao.RoleDAO;
import com.alisls.shequtao.service.user.dto.RoleDTO;
import com.alisls.shequtao.service.user.entity.RoleDO;
import com.alisls.shequtao.service.user.exception.UserEnumException;
import com.alisls.shequtao.service.user.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * 角色Service实现
 *
 * @author Ke Wang
 */
@Service("roleService")
@AllArgsConstructor
public class RoleServiceImpl extends ServiceImpl<RoleDAO, RoleDO> implements RoleService {

	private final RoleDAO roleDAO;
	
	@Override
	public RoleDTO getRoleById(Long id) {
		RoleDO roleDO = this.getById(id);
		if (roleDO == null) {
			throw UserEnumException.of(UserExceptionEnum.ROLE_NOT_FOUND);
		}
		
		RoleDTO roleDTO = new RoleDTO();
		BeanUtils.copyProperties(roleDO, roleDTO);
		return roleDTO;
	}

}
